package com.stox.charting.ui.swing.model;

import java.awt.Graphics;
import java.awt.Point;
import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionListener;

import com.stox.core.ui.swing.wrapper.JComponent;

public class Crosshair extends JComponent implements MouseMotionListener {
	private static final long serialVersionUID = -4847856271136922831L;

	private Point point;
	
	@Override
	public void mouseDragged(MouseEvent e) {
		mouseMoved(e);
	}
	
	@Override
	public void mouseMoved(MouseEvent e) {
		point = e.getPoint();
		repaint();
	}
	
	@Override
	protected void paintComponent(Graphics g) {
		if(point != null){
			super.paintComponent(g);			
			g.setColor(Theme.getColours().getCrosshair());
			g.drawLine((int)point.getX(), getY(), (int)point.getX(), getY()+getHeight());
			g.drawLine(getX(), (int)point.getY(), getX()+getWidth(), (int)point.getY());
		}
	}
	
}
